/*
 * @lc app=leetcode.cn id=1652 lang=typescript
 *
 * [1652] 拆炸弹
 */

// @lc code=start
function decrypt(code: number[], k: number): number[] {
    if (k === 0) return code.map(() => 0);

    const final = (k > 0 ? code : code.reverse()).map((i, index) => {
        let count = Math.abs(k);
        let total = 0;
        while (count) {
            total += code[(index + count) % code.length];

            count--;
        }
        return total;
    });
    return k > 0 ? final : final.reverse();
}
// @lc code=end
